import { defineStore } from 'pinia'

export const useLayoutStore = defineStore('layout', {
  state: () => {
    return {
      collapse: false,
      menuWith: '250px',
      tagviews: [] as any[],
      layoutType:false
    }
  },
  getters: {},
  actions: {
    //添加tag
    addTagViews(newTag: any) {
      const hasTag = this.tagviews.findIndex((t: any) => { return t.path == newTag.path })
      if (hasTag === -1) {
        this.tagviews.push(newTag)
      }
    },
    //删除tag
    deleteTagViews(newTag:any){
      this.tagviews = this.tagviews.filter(t => {
        if(this.tagviews.length > 1){
          return t.path != newTag.path
        }
      })
    },
    //初始化tag
    initTagViews(newTag:any){
      if(this.tagviews.length <= 0){
        this.tagviews.push(newTag)
      }
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        key: 'layot',
        storage: localStorage,
      }
    ]
  }
})